package org.bambrikii.examples.rutext.lexer.impl;

import java.util.Map;

import org.bambrikii.examples.rutext.dictionary.DoubleDictionaryLoader;
import org.bambrikii.examples.rutext.lexer.CaseValue;
import org.bambrikii.examples.rutext.lexer.impl.LexerBase;
import org.bambrikii.examples.rutext.parser.IParser;
import org.bambrikii.examples.rutext.parser.ParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FractionPowLexer extends LexerBase<Double> {

	private static final Logger logger = LoggerFactory.getLogger(FractionPowLexer.class);

	private static Map<String, Double> DICT = null;
	private static Map<String, CaseValue> DICT_CASES = null;

	static {
		DoubleDictionaryLoader loader = new DoubleDictionaryLoader();
		DICT = loader.load("org.bambrikii.examples.rutext.FractionPowLexer", "FRACTION_POWS");
		DICT_CASES = loader.loadCases("org.bambrikii.examples.rutext.FractionPowLexer", "FRACTION_POWS__CASES");
	}

	static Double findValue(String val) {
		if (DICT.containsKey(val)) {
			return DICT.get(val);
		}
		if (DICT_CASES.containsKey(val)) {
			return DICT.get(DICT_CASES.get(val).getKey());
		}
		return null;
	}

	public FractionPowLexer(IParser parser) {
		super(parser);
	}

	@Override
	public Double lex() throws ParserException {
		if (hasNext()) {
			String val = getLast();
			Double val2 = findValue(val);
			if (val2 != null) {
				logger.debug("success [" + val + "]");
				consume();
				return val2;
			}
		}
		return null;
	}

}
